<?php

/*

  Action	$5

  +1 Card; +1 Action
  Trash a card from your hand.
  Gain a card costing exactly $1 more than it.

 */

class Upgrade extends Card implements iAction, iKingdom, iIntrigue {

    public function __construct() {
        parent::__construct("Upgrade", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Card",
            "+1 Action",
            "Trash a card from your hand.  Gain a card costing exactly $1 more than it.");
    }
    
    public function play(Game $game, $isRealCard) {

        $game->addActions(1);
        $drawed_cards = $game->drawCards(1);
        
         ScreenDisplay::addScreenMessage($game, true, "get +1 action and draw ". nicePrint($drawed_cards), "gets +1 action and draws ".sizeof($drawed_cards) . " cards");

        $playHand = $game->getPlayHand();
        if (sizeof($playHand) > 0) {

			$playHand = getUniqueCards($playHand);
			if (sizeof($playHand) > 1) {
				$output = MySocket::GetUserReply($game, Input_ChooseOne, $playHand, 1, 1, null,"Choose card to trash");
				$card_name = $output[0];
			}
			else {
				$card_name = $playHand[0];
			}

            //trash it
            $card = $game->moveCardFromPileToPile($card_name, PlayHand, Trash);
            ScreenDisplay::addScreenMessage($game, true, "trash ". nicePrint($card), "trashes ".ScreenDisplay::$LMSG);   
            //now get the price and offer option to the player
            $price = $card->getPrice($game);
            $new_price = $price->add(1);
            $optional_cards = $game->getBoardCardsByPrice($new_price, $new_price);

            if (sizeof($optional_cards) > 0) {
   
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $optional_cards, 1, 1, null, "Choose a card to gain");
                $card_name = $output[0];
                $card = $game->moveCardFromPileToPile($card_name, BoardCards, DiscardPile);
                 ScreenDisplay::addScreenMessage($game, false, " and gain ". nicePrint($card), " and gains ".ScreenDisplay::$LMSG);   
            }
            else {
                 ScreenDisplay::addScreenMessage($game, false, " and gain nothing", " and gains nothing");   
            }    
        }
		else {
			ScreenDisplay::addScreenMessage($game, true, "trash nothing", "trashes nothing");   
		}
        $game->cardActionFinished();
        return true;
    }

}

?>